"""
使用了 bibtexparser
https://bibtexparser.readthedocs.io/en/master/tutorial.html
"""
import bibtexparser
from translate import get_translate


def abs_proc(abs_en):
    abs_ch = get_translate(abs_en, tl='zh-CN')
    result_ch = ''
    for setence in abs_ch:
        if setence[0] is not None:
            result_ch+=setence[0]
    result_ch=result_ch.replace('我们','本文作者')
    return result_ch


with open('article.bib') as bibtex_file:
    bib_database = bibtexparser.load(bibtex_file)

entries = bib_database.entries
with open('docx_pre.tmp','w',encoding="utf-8") as cls:
    cls.write("#generate from bibTex\n")


with open('docx_pre.tmp','a',encoding="utf-8") as docx_pre:
    for bib_index,entry in enumerate(entries):
        print(bib_index+1,file=docx_pre)
        print(entry['title'],file=docx_pre)
        abs_processed = abs_proc(entry['abstract'])
        print(abs_processed,file=docx_pre)
        print("我的启发",file=docx_pre)



